<?php

namespace app\modules\Admin\models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;

class scoregoodsModel extends Model
{
    protected $table = 'score_goods';
    protected $primaryKey = 'id';
    protected $appends = ['status_text'];

    protected $hidden = [];


    protected static array $statuss = [
        'up'=>'上架',
        'down'=>'下架',
    ];

    /**
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function getStatusTextAttribute()
    {
        $status_text = '';
        $status_key = array_keys(self::$statuss);
        if(in_array($this->attributes['status'], $status_key)){
            $status_text = self::$statuss[$this->attributes['status']];
        }
        unset($status_key);
        return $status_text;
    }

    public function goods()
    {
        return $this->hasOne(\goodsModel::class, 'id', 'goods_id');
    }

    public function goods_sku_price()
    {
        return $this->hasOne(\goodsskupriceModel::class, 'id', 'sku_price_id');
    }

    public function score_sku()
    {
        return $this->hasMany(get_class($this), 'goods_id', 'goods_id');
    }
}